<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const directLine = testHelpers.createDirectLineWithTranscript([
          {
            attachments: [
              {
                contentType: 'application/vnd.microsoft.card.adaptive',
                content: {
                  type: 'AdaptiveCard',
                  $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
                  version: '1.3',
                  body: [
                    {
                      type: 'Input.Text',
                      placeholder: 'Placeholder text',
                      isRequired: true,
                      errorMessage: 'Error message',
                      label: 'Label',
                      id: 'id-1'
                    }
                  ]
                }
              }
            ],
            from: {
              id: 'bot',
              role: 'bot'
            },
            id: '1',
            timestamp: new Date().toISOString(),
            type: 'message'
          }
        ]);

        const store = testHelpers.createStore();

        function renderWebChatWithMaxVersion(adaptiveCardsParserMaxVersion) {
          WebChat.renderWebChat(
            {
              directLine,
              store,
              styleOptions: {
                adaptiveCardsParserMaxVersion
              }
            },
            document.getElementById('webchat')
          );
        }

        renderWebChatWithMaxVersion();

        await pageConditions.uiConnected();

        // When no maxVersion is specified, it should use the latest.
        // The screenshot should have the "Label" text.
        await host.snapshot('local');

        // When maxVersion is specified, it should use that version.
        // The screenshot should not have the "Label" text, as it was introduced in 1.3.
        renderWebChatWithMaxVersion('1.2');
        await host.snapshot('local');

        // When maxVersion is specified but invalid, it should use the latest.
        // The screenshot should have the "Label" text.
        renderWebChatWithMaxVersion('x.y.z');
        await host.snapshot('local');
      });
    </script>
  </body>
</html>
